package com.soc.erp.operRecord;

import java.util.List;

import org.nature.framework.annotation.Ask;
import org.nature.framework.annotation.Ctrl;
import org.nature.framework.annotation.Inject;
import org.nature.framework.core.NatureCtrl;
import org.nature.framework.core.NatureMap;
import org.nature.framework.util.StringUtil;

import com.soc.erp.index.IService;

@SuppressWarnings("serial")
@Ctrl(namespace="/operRecord")
public class OperRecordCtrl extends NatureCtrl {
	public OperRecord operRecord = new OperRecord();
	public List<NatureMap> users;
	public String ask;
	//public String time1 = new String();
	//public String time2 = new String();
	
	@Inject
	OperRecordService operRecordService;
	
	@Inject
	IService iService;
 
	
	@Ask
	public Object list(){
		//String sql = "select r.*,u.name from tb_oper_record r left join tb_contact u on r.userid=u.id where 1=1 ";
		//String sql = "select t1.*,t2.real_name as rname,t3.company_name as cname from tb_oper_record t1 left join tb_member  t2 on t1.userid=t2.member_id left join tb_dealer t3 on t1.userid=t3.dealer_id  where 1=1 ";
		String sql = "select r.*,u.real_name from tb_oper_record r left join tb_system_user u on r.userid=u.id where  role_type = 0 ";
		
		if (StringUtil.isNotBank(operRecord.getString("search_date_start")))
			sql += String.format(" and date(oper_time) >= '%s'", operRecord.getString("search_date_start"));
		 

		if (StringUtil.isNotBank(operRecord.getString("search_date_end")))
			sql += String.format(" and date(oper_time) <= '%s'", operRecord.getString("search_date_end"));
		
		if (StringUtil.isNotBank(operRecord.getString(OperRecord.userid))){
			sql+=" and u.real_name like '%"+operRecord.getString(OperRecord.userid)+"%'";
		}
		
		sql += " order by oper_time desc";
		page = operRecordService.page(page, sql);
		iService.jsPage(page, "jsPage");
		return "list.ftl";
	}
	

	
}
